package pathFinder.bfs;


import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

public class Node implements Comparable<Node> {
	/* Nodes that this is connected to */
	//AreaMap map;
	public int id_airport;
	String name;
	List<Edge> connectionList;
	boolean visited;
	float distanceFromStart;
	float heuristicDistanceFromGoal;
	float departureHour;
	Node previousNode;
	public boolean isStart;
	public boolean isGoal;
	public boolean isPath;
	
	Node(String name) {
		this.name = name;
		this.visited = false;
		this.distanceFromStart = Integer.MAX_VALUE;
		this.isStart = false;
		this.isGoal = false;
		connectionList = new ArrayList<>();		
	}
	
	Node (boolean visited, int distanceFromStart, boolean isStart, boolean isGoal) {

	//	this.map = map;
		this.visited = visited;
		this.distanceFromStart = distanceFromStart;
		this.isStart = isStart;
		this.isGoal = isGoal;
	}
	
	public String getName(){
		return name;
	}
	public ArrayList<Node> getNeighborList() {
		ArrayList<Node> neighborList = new ArrayList<Node>();
		for(int i = 0; i <connectionList.size(); i++){
			neighborList.add((connectionList.get(i).getDestination()));
		}
		return neighborList;
	}

	public boolean isVisited() {
		return visited;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public float getDistanceFromStart() {
		return distanceFromStart;
	}

	public void setDistanceFromStart(float f) {
		this.distanceFromStart = f;
	}

	public Node getPreviousNode() {
		return previousNode;
	}

	public void setPreviousNode(Node previousNode) {
		this.previousNode = previousNode;
	}
	
	public void setDepartureHour(float hour){
		this.departureHour = hour;
	}
	public float getHeuristicDistanceFromGoal() {
		return heuristicDistanceFromGoal;
	}

	public void setHeuristicDistanceFromGoal(float heuristicDistanceFromGoal) {
		this.heuristicDistanceFromGoal = heuristicDistanceFromGoal;
	}


	public  float getDistanceTo(Node next){
		float rez = 10000;
		for(int i = 0; i <connectionList.size(); i++){
			Edge e = connectionList.get(i);
			if(e.to ==next.name){
				rez = e.getDurationFlight()+e.getHourDeparture();
			}
		}
		return rez;
	}

	public boolean isStart() {
		return isStart;
	}

	public void setStart(boolean isStart) {
		this.isStart = isStart;
	}

	public boolean isGoal() {
		return isGoal;
	}

	public void setGoal(boolean isGoal) {
		this.isGoal = isGoal;
	}

	public boolean isPath() {
		return isPath;
	}

	public void setPath(boolean isPath) {
		this.isPath = isPath;
	}

	public boolean equals(Node node) {
		return id_airport == node.id_airport;
	}
	
	public int getId(){
		return id_airport;
	}

	public int compareTo(Node otherNode) {
		float thisTotalDistanceFromGoal = heuristicDistanceFromGoal + distanceFromStart;
		float otherTotalDistanceFromGoal = otherNode.getHeuristicDistanceFromGoal() + otherNode.getDistanceFromStart();
		
		if (thisTotalDistanceFromGoal < otherTotalDistanceFromGoal) {
			return -1;
		} else if (thisTotalDistanceFromGoal > otherTotalDistanceFromGoal) {
			return 1;
		} else {
			return 0;
		}
	}
	
	public String toString(){
		String rez ="";
		rez += this.name+" "+this.id_airport+"\n";
		for(int i = 0; i < this.connectionList.size(); i++){
			rez+="\t"+connectionList.get(i).to+";\n";
		}
		return rez;
	}
}